﻿using System;

namespace KuiHuaBaoDian.Services.Lockstep {

    /// <summary>
    /// 帧同步计时器句柄
    /// </summary>
    public readonly struct LockstepTimerHandle {

        /// <summary>
        /// 空值
        /// </summary>
        public static readonly LockstepTimerHandle None = new();

        /// <summary>
        /// GUID
        /// </summary>
        public Guid GUID { get; init; }

        public override readonly string ToString() => $"[{nameof(LockstepTimerHandle)}({GUID})]";

        public override readonly int GetHashCode() => GUID.GetHashCode();

        public override bool Equals(object obj) {
            if (obj is LockstepTimerHandle other) {
                return other.GUID == GUID;
            }
            return false;
        }

        public static bool operator ==(LockstepTimerHandle left, LockstepTimerHandle right) => left.Equals(right);
        public static bool operator !=(LockstepTimerHandle left, LockstepTimerHandle right) => !left.Equals(right);

        public static explicit operator LockstepTimerHandle(LockstepEntityHandle @in) => new() { GUID = @in.GUID };

        public static implicit operator LockstepEntityHandle(LockstepTimerHandle @in) => new() { GUID = @in.GUID };
    }
}
